package com.ytweb.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ytweb.model.People;
import com.ytweb.service.PeoplelistService;
@Controller
public class PeoplelistController {
	@Autowired 
	private PeoplelistService mapService;
	@RequestMapping(value="/getPeopleList",method = RequestMethod.GET)  
    @ResponseBody  
    public Map<String,Object> getPeopleList(HttpServletRequest request,HttpServletResponse res){ 
		res.setHeader("Access-Control-Allow-Origin","*");
        System.out.println("进入拦截");
        //获取每页记录数  
        int limit = 10;
        //获取当前页数  
        int page = Integer.parseInt(request.getParameter("page"));
        //查询总记录数  
        int total = mapService.countNumb();  
        //计算分页数
        int ptotal;
        if(total%limit==0) {
        	ptotal=total/limit;
        }else {
        	ptotal=total/limit+1;
        }
        Map<String, Object> map = new HashMap<String,Object>(); 
        map.put("ptotal",ptotal);
        //查询当前页面需要的数据  
        List<People> pList = mapService.getPeopleList(page,limit);  
        map.put("pList", pList);  
        return map;  
    }

}
